package com.slife.snap.utils;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ListUtils {

    public static Double getMaxValue(List<Double> integerList){

        Map<Double, Integer> countMap = new HashMap<>();

        for (double num : integerList) {
            countMap.put(num, countMap.getOrDefault(num, 0) + 1);
        }

        int maxCount = 0;
        Double mostFrequentNumber = 0.00;
        for (Map.Entry<Double, Integer> entry : countMap.entrySet()) {
            Double number = entry.getKey();
            int count = entry.getValue();
            if (count > maxCount) {
                maxCount = count;
                mostFrequentNumber = number;
            }
        }

        return mostFrequentNumber;

    }

    public static Double getRoudValue(double value){
        return new BigDecimal(value).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();

    }

}
